/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Services;

import DAO.DAOFactory;
import DAO.Financial.MarketDAO;
import DAO.Financial.StockDAO;
import DAO.exceptions.PreexistingEntityException;
import FinancialEntity.Market;
import FinancialEntity.Stock;
import VO.MarketVO;
import VO.StockVO;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author Sebastian
 */
public class StockService {
    
    public void createStock(StockVO stockVo, EntityManager em ) throws PreexistingEntityException, Exception{
        StockDAO stockdao = (StockDAO) DAOFactory.getDAOFinancial(DAOFactory.STOCK);
        stockdao.create(stockVo.toEntity(), em);
    }
    
    public List<StockVO> getAllStocks(EntityManager em){
        StockDAO stockdao = (StockDAO) DAOFactory.getDAOFinancial(DAOFactory.STOCK);
        List<Stock> listaAcciones = stockdao.findStockEntities(em);
        List<StockVO> listaVos = new ArrayList<>();
        for (Stock m:listaAcciones){
            listaVos.add(m.toVO());
        }
        return listaVos;
    }
    
}
